package com.qth.valet.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qth.valet.common.theadlocal.UserOrDriverIdHolder;
import com.qth.valet.common.utils.ResponseResult;
import com.qth.valet.entity.vo.CouponUserVo;
import com.qth.valet.service.CouponUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 蔡徐坤
 * @since 2025-08-26
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/qth/coupon")
public class CouponController {

    private final CouponUserService couponUserService;

    /**
     * 用户查询自己的全部优惠券
     */
    @GetMapping("/getMyCouponList")
    public ResponseResult<List<CouponUserVo>> getMyCouponList() {
        return ResponseResult.success(couponUserService.getMyCouponList(UserOrDriverIdHolder.getUserId()));
    }

    /**
     * 查询可用优惠券数量
     */
    @GetMapping("/getMyCouponCount")
    public ResponseResult<Long> getMyCouponCount() {
        return ResponseResult.success(couponUserService.getMyCouponCount(UserOrDriverIdHolder.getUserId()));
    }

    @GetMapping("/getMyCouponListBySts")
    public ResponseResult<IPage<CouponUserVo>> getMyCouponList(Integer status,
                                                               @RequestParam(defaultValue = "1") int pageNum,
                                                               @RequestParam(defaultValue = "10") int pageSize) {
        Page<CouponUserVo> page = new Page<>(pageNum, pageSize);
        return ResponseResult.success(couponUserService.getMyCouponBySts(page, UserOrDriverIdHolder.getUserId(), status));
    }

}
